﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Text.RegularExpressions;

namespace DataAccessComponents
{
    public class DaneFirma : IDataErrorInfo
    {
        /// <summary>
        /// Nazw firmy
        /// </summary>
        private string nazwa;

        public string Nazwa
        {
            get { return nazwa; }
            set { nazwa = value; }
        }

        /// <summary>
        /// Id adresu
        /// </summary>
        private int id_adres;

        public int Id_adres
        {
            get { return id_adres; }
            set { id_adres = value; }
        }

        public Adres Adres { get; set; }

        /// <summary>
        /// Opis firmy
        /// </summary>
        private string opis;

        public string Opis
        {
            get { return opis; }
            set { opis = value; }
        }

        /// <summary>
        /// Haslo do smtp
        /// </summary>
        private string haslo_smtp;

        public string Haslo_smtp
        {
            get { return haslo_smtp; }
            set { haslo_smtp = value; }
        }

        /// <summary>
        /// Login do smtp
        /// </summary>
        private string login_smtp;

        public string Login_smtp
        {
            get { return login_smtp; }
            set { login_smtp = value; }
        }

        /// <summary>
        /// Adres hosta smtp
        /// </summary>
        private string host_smtp;

        public string Host_smtp
        {
            get { return host_smtp; }
            set { host_smtp = value; }
        }

        /// <summary>
        /// Haslo do uslugi sms
        /// </summary>
        private string haslo_sms;

        public string Haslo_sms
        {
            get { return haslo_sms; }
            set { haslo_sms = value; }
        }

        /// <summary>
        /// Login do usługi sms
        /// </summary>
        private string login_sms;
        
        public string Login_sms
        {
            get { return login_sms; }
            set { login_sms = value; }
        }

        /// <summary>
        /// Adres hosta sms
        /// </summary>
        private string host_sms;

        public string Host_sms
        {
            get { return host_sms; }
            set { host_sms = value; }
        }

        /// <summary>
        /// Email
        /// </summary>
        private string email_smtp;

        public string Email_smtp
        {
            get { return email_smtp; }
            set { email_smtp = value; }
        }

        public DaneFirma()
        {
            this.nazwa = "";
            this.id_adres = 0;
            this.opis = "";
            this.haslo_sms = "";
            this.login_sms = "";
            this.host_smtp = "";
            this.haslo_smtp = "";
            this.login_smtp= "";
            this.host_smtp = "";
            this.email_smtp = "";
        }

        public string Error
        {
            get { return string.Empty; }
        }

        public string this[string propertyName]
        {
            get {
                string result = string.Empty;
                propertyName = propertyName ?? string.Empty;

                if (propertyName == "Nazwa")
                {
                    if (string.IsNullOrEmpty(this.Nazwa))
                    {
                        result = "Pole \"Nazwa\" nie może być puste";
                    }
                    else if (Regex.IsMatch(this.Nazwa, @"[@£_^{}\[~\]|ÆæßÉ!¤%&'()\*\+,-.:;<=>§?]+"))
                    {
                        result = "Pole \"Nazwa\" zawiera niedozwolone znaki";
                    }
                }
                else if (propertyName == "Haslo_smtp")
                {
                    if (string.IsNullOrEmpty(this.Haslo_smtp))
                    {
                        result = "Pole \"Haslo_smtp\" nie może być puste";
                    }
                    //else if (Regex.IsMatch(this.Haslo_smtp, @"[@£_^{}\[~\]|ÆæßÉ!¤%&'()\*\+,-.:;<=>§?]+"))
                    //{
                    //    result = "Pole \"Haslo_smtp\" zawiera niedozwolone znaki";
                    //}
                }
                else if (propertyName == "Login_smtp")
                {
                    if (string.IsNullOrEmpty(this.Login_smtp))
                    {
                        result = "Pole \"Login_smtp\" nie może być puste";
                    }
                    //else if (Regex.IsMatch(this.Login_smtp, @"[@£_^{}\[~\]|ÆæßÉ!¤%&'()\*\+,-.:;<=>§?]+"))
                    //{
                    //    result = "Pole \"Login_smtp\" zawiera niedozwolone znaki";
                    //}
                }
                else if (propertyName == "Host_smtp")
                {
                    if (string.IsNullOrEmpty(this.Host_smtp))
                    {
                        result = "Pole \"Host_smtp\" nie może być puste";
                    }else if(!Regex.IsMatch(this.Host_smtp,@"^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$")){
                        result = "Pole \"Host_smtp\" zawiera niepoprawny adres";
                    }
                    else if (Regex.IsMatch(this.Host_smtp, @"[@£_^{}[~]|ÆæßÉ!¤%&'()\*\+,-;<=>§?]+"))
                    {
                        result = "Pole \"Host_smtp\" zawiera niedozwolone znaki";
                    }
                } else if (propertyName == "Email_smtp")
                {
                    if (string.IsNullOrEmpty(this.Email_smtp))
                    {
                        result = "Pole \"Email\" nie może być puste";
                    }
                    else if (!Regex.IsMatch(this.Email_smtp, @"^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$"))
                    {
                        result = "Pole \"Email\" zawiera nie poprawny adres email";
                    }
                }
                else if (propertyName == "Haslo_sms")
                {
                    if (string.IsNullOrEmpty(this.Haslo_sms))
                    {
                        result = "Pole \"Haslo_sms\" nie może być puste";
                    }
                    //else if (Regex.IsMatch(this.Haslo_sms, @"[@£_^{}\[~\]|AaßÉ!¤%&'()\*\+,-.:;<=>§?]+"))
                    //{
                    //    result = "Pole \"Haslo_sms\" zawiera niedozwolone znaki";
                    //}
                }
                else if (propertyName == "Login_sms")
                {
                    if (string.IsNullOrEmpty(this.Login_sms))
                    {
                        result = "Pole \"Login_sms\" nie może być puste";
                    }
                    //else if (Regex.IsMatch(this.Login_sms, @"[@£_^{}\[~\]|ÆæßÉ!¤%&'()\*\+,-.:;<=>§?]+"))
                    //{
                    //    result = "Pole \"Login_sms\" zawiera niedozwolone znaki";
                    //}
                }
                else if (propertyName == "Host_sms")
                {
                    if (string.IsNullOrEmpty(this.Host_sms))
                    {
                        result = "Pole \"Host_sms\" nie może być puste";
                    }else if(!Regex.IsMatch(this.Host_sms,@"^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$")){
                        result = "Pole \"Host_sms\" zawiera niepoprawny adres";
                    }
                    else if (Regex.IsMatch(this.Host_sms, @"[@£_^{}[~]|ÆæßÉ!¤%&'()\*\+,;<=>§?]+"))
                    {
                        result = "Pole \"Host_sms\" zawiera niedozwolone znaki";
                    }
                }

                return result;
            }
        }
    }
}
